--G4键启动小怪宏，G5键启动跑路宏，G3键启动BOSS宏，大小写键关闭宏
--辅助键+G4一件分解，辅助键+鼠标右键一键赌博，辅助键+鼠标左键一键拾取
--默认键位：金轮阵、炫目闪、飓风破、灵光悟、断筋诀、真言
---------------------------------------------------------------------------------------------------------
XiaoGuai = 4  --自行修改小怪启动键
PaoLu = 5  --自行修改跑路启动键
BOSS = 3  --自行修改王战启动键

LED = "capslock" --自行修改指示灯按键（可改为"scrolllock"或"numlock"）
ZhanLi = "lshift" --自行修改强制站立键（空格为"Spacebar"）
FuZhu = "lctrl"  --自行修改辅助键（无需一键功能修改为"rshift"即可）
BiLi = { 16, 9 }--屏幕比例
QieHuan = 1 --自行修改切换方式（0.单开单关、1.无缝切换）

--属性设置
GongSu = 2.29--站街面板攻速

--小怪设置
XuanMuYanChi = 500--炫目闪释放间隔
ZhenYanYanChi = 100--真言释放间隔
HeiRenYanChi = 500--黑人释放间隔
JuFengYanChi = 4000--飓风破释放间隔
JinZhenYanChi = 500--金轮阵释放间隔

--跑路设置
HeiRenPaoLu = 500--跑路黑人释放间隔
ZhenYanPaoLu = 500--跑路真言释放间隔

--王战设置
BOSSJianGe = 3000--王战飓风破间隔（0则不打飓风破）
BOSSYanChi = 1600--王战不打飓风破时打拳间隔
BOSSZhenYan = 800--王战真言释放间隔

AnJian = { "1", "2", "3", "4", "Left", "Right" }--技能栏按键设置
--技能从左往右顺序
jlz = AnJian[1]--金轮阵技能栏位置
xms = AnJian[2]--炫目闪技能栏位置
jfp = AnJian[3]--飓风破技能栏位置
hr = AnJian[4]--黑人技能栏位置
djj = AnJian[5]--断筋决技能栏位置
zy = AnJian[6]--真言技能栏位置
---------------------------------------------------全局设置-----------------------------------------------
EnablePrimaryMouseButtonEvents(true)

--计算公式
JuFengZhenShu = math.ceil(60 / GongSu)--飓风破站街帧数
JinZhenZhenShu = math.ceil(60 / GongSu)--金轮阵站街帧数
JuFengShiJian = 60000 / JinZhenZhenShu

function JiNeng_Down(JiNeng)
    if JiNeng == "Left" then
        PressMouseButton(1)--点击左键
    elseif JiNeng == "Right" then
        PressMouseButton(3)--点击右键
    else
        PressKey(JiNeng)
    end
end

function JiNeng_Up(JiNeng)
    if JiNeng == "Left" then
        ReleaseMouseButton(1)--释放左键
    elseif JiNeng == "Right" then
        ReleaseMouseButton(3)--释放右键
    else
        ReleaseKey(JiNeng)
    end
end

if XiaoGuai == 2 then
    XiaoGuaiButton = 3
elseif XiaoGuai == 3 then
    XiaoGuaiButton = 2
else
    XiaoGuaiButton = XiaoGuai
end

if PaoLu == 2 then
    PaoLuButton = 3
elseif PaoLu == 3 then
    PaoLuButton = 2
else
    PaoLuButton = PaoLu
end

if BOSS == 2 then
    BOSSButton = 3
elseif BOSS == 3 then
    BOSSButton = 2
else
    BOSSButton = BOSS
end

KaiGuan = 1
KaiGuan_ZhuangTai = 0

--开启
function KaiQi()
    if KaiGuan == 1 then
        PressAndReleaseKey(LED)
        KaiGuan_ZhuangTai = 1
    elseif KaiGuan == 0 then
        --重置宏状态
        KaiGuan = 1
    end
end

--关闭
function GuanBi(K)
    if not IsMouseButtonPressed(K) and KaiGuan_ZhuangTai == 1 then
        --判断是否松开启动键
        KaiGuan_ZhuangTai = 0
    elseif IsMouseButtonPressed(XiaoGuaiButton) and KaiGuan_ZhuangTai == 0 then
        --关闭宏
        KaiGuan = 0
        PressAndReleaseKey(LED)
    elseif IsMouseButtonPressed(PaoLuButton) and KaiGuan_ZhuangTai == 0 then
        --关闭宏
        KaiGuan = 0
        PressAndReleaseKey(LED)
    elseif IsMouseButtonPressed(BOSSButton) and KaiGuan_ZhuangTai == 0 then
        --关闭宏
        KaiGuan = 0
        PressAndReleaseKey(LED)
    end
end

--分解
function FenJie()
    MoveMouseToVirtual(6000 * 16 * BiLi[2] / 9 / BiLi[1], 17000)
    Sleep(100)
    PressAndReleaseMouseButton(1)
    Sleep(50)
    k = 0
    while k < 60
    do
        X = k % 10-- 分解列
        Y = math.floor(k / 10)--分解行
        MoveMouseToVirtual(65535 - (65535 - 49000 - 1700 * X) * 16 * BiLi[2] / 9 / BiLi[1], 36000 + 3000 * Y)
        Sleep(1)
        PressAndReleaseMouseButton(1)
        Sleep(1)
        PressAndReleaseKey("Enter")
        Sleep(1)
        PressAndReleaseMouseButton(1)
        Sleep(1)
        PressAndReleaseKey("Enter")
        Sleep(1)
        k = k + 1
    end
end
---------------------------------------------------技能设置-----------------------------------------------
--小怪延迟
function XiaoGuaiYanChi(ZhenShu)
    if IsKeyLockOn(LED) then
        --判断是否灯亮
        XianZai = GetRunningTime()--得到延迟脚本开始时间
        while XianZai - KaiShi < (XianZai_ZhenShu + ZhenShu) / 60 * 1000 and IsKeyLockOn(LED)--如果延迟时间不达到预设时间则一直等待,如果灯灭,则直接中断延迟。
        do
            GuanBi(XiaoGuaiButton)
            if not IsMouseButtonPressed(1) then
                ReleaseMouseButton(1)
                PressMouseButton(1)
            end
            if XuanMu == 0 then
                --判断炫目闪冷却是否结束
                JiNeng_Down(xms)
                JiNeng_Up(xms)
                XuanMu = 1
                XuanMuShiJian = GetRunningTime()
            elseif XuanMu == 1 and HeiRen == 1 and ZhenYan == 1 and JinZhen == 1 and JuFeng == 1 and XianZai - XuanMuShiJian > XuanMuYanChi then
                --判断炫目闪是否释放
                XuanMu = 0
            end
            if HeiRen == 0 then
                --判断黑人冷却是否结束
                JiNeng_Down(hr)
                JiNeng_Up(hr)
                HeiRen = 1
                HeiRenShiJian = GetRunningTime()
            elseif XuanMu == 1 and HeiRen == 1 and ZhenYan == 1 and JinZhen == 1 and JuFeng == 1 and XianZai - HeiRenShiJian > HeiRenYanChi then
                --判断黑人是否释放
                HeiRen = 0
            end
            if ZhenYan == 0 then
                --判断真言冷却是否结束
                JiNeng_Down(zy)
                JiNeng_Up(zy)
                ZhenYan = 1
                ZhenYanShiJian = GetRunningTime()
            elseif XuanMu == 1 and HeiRen == 1 and ZhenYan == 1 and JinZhen == 1 and JuFeng == 1 and XianZai - ZhenYanShiJian > ZhenYanYanChi then
                --判断真言是否释放
                ZhenYan = 0
            end
            if JinZhen == 0 then
                --判断金轮阵冷却是否结束
                JiNeng_Down(jlz)
                JiNeng_Up(jlz)
                JinZhen = 1
                JinZhenShiJian = GetRunningTime()
            elseif XuanMu == 1 and HeiRen == 1 and ZhenYan == 1 and JinZhen == 1 and JuFeng == 1 and XianZai - JinZhenShiJian > JinZhenYanChi then
                --判断金轮阵是否释放
                if JinZhenShiJian > JuFengShiJian and JinZhenShiJian + JinZhenYanChi < JuFengShiJian + JuFengYanChi - JinZhenZhenShu / 60 * 1000 then
                    JinZhen = 0
                elseif JinZhenShiJian < JuFengShiJian and XianZai - JuFengShiJian > JuFengZhenShu / 60 * 1000 then
                    JinZhen = 0
                end
            end
            if JuFeng == 0 then
                --判断飓风破冷却是否结束
                JiNeng_Down(jfp)
                JiNeng_Up(jfp)
                JuFeng = 1
                JuFengShiJian = GetRunningTime()
            elseif XuanMu == 1 and HeiRen == 1 and ZhenYan == 1 and JinZhen == 1 and JuFeng == 1 and XianZai - JuFengShiJian > JuFengYanChi then
                --判断飓风破是否释放
                JuFeng = 0
            end
            Sleep(1)
            XianZai = GetRunningTime()--得到延迟脚本过程的绝对时间
        end
        XianZai_ZhenShu = XianZai_ZhenShu + ZhenShu
    end
end

--跑路延迟
function PaoLuYanChi(ZhenShu)
    if IsKeyLockOn(LED) then
        --判断是否灯亮
        XianZai = GetRunningTime()--得到延迟脚本开始时间
        while XianZai - KaiShi < (XianZai_ZhenShu + ZhenShu) / 60 * 1000 and IsKeyLockOn(LED)
        do
            GuanBi(PaoLuButton)
            if HeiRen == 0 then
                --判断黑人冷却是否结束
                JiNeng_Down(hr)
                JiNeng_Up(hr)
                HeiRen = 1
                HeiRenShiJian = GetRunningTime()
            elseif HeiRen == 1 and ZhenYan == 1 and XianZai - HeiRenShiJian > HeiRenPaoLu then
                --判断黑人是否释放
                HeiRen = 0
            end
            if ZhenYan == 0 then
                --判断真言冷却是否结束
                JiNeng_Down(zy)
                JiNeng_Up(zy)
                ZhenYan = 1
                ZhenYanShiJian = GetRunningTime()
            elseif HeiRen == 1 and ZhenYan == 1 and XianZai - ZhenYanShiJian > ZhenYanPaoLu then
                --判断真言是否释放
                ZhenYan = 0
            end
            Sleep(1)
            XianZai = GetRunningTime()--得到延迟脚本过程的绝对时间
        end
        XianZai_ZhenShu = XianZai_ZhenShu + ZhenShu
    end
end

--BOSS无飓风
function BOSSYanChi1(ZhenShu)
    if IsKeyLockOn(LED) then
        --判断是否灯亮
        XianZai = GetRunningTime()--得到延迟脚本开始时间
        while XianZai - KaiShi < (XianZai_ZhenShu + ZhenShu) / 60 * 1000 and IsKeyLockOn(LED)
        do
            GuanBi(BOSSButton)
            if HeiRen == 0 then
                --判断黑人冷却是否结束
                JiNeng_Down(hr)
                JiNeng_Up(hr)
                HeiRen = 1
                HeiRenShiJian = GetRunningTime()
            elseif Duanjin == 1 and HeiRen == 1 and ZhenYan == 1 and JinZhen == 1 and JuFeng == 1 and XianZai - HeiRenShiJian > HeiRenYanChi then
                --判断黑人是否释放
                HeiRen = 0
            end
            if ZhenYan == 0 then
                --判断真言冷却是否结束
                JiNeng_Down(zy)
                JiNeng_Up(zy)
                ZhenYan = 1
                ZhenYanShiJian = GetRunningTime()
            elseif Duanjin == 1 and HeiRen == 1 and ZhenYan == 1 and JinZhen == 1 and JuFeng == 1 and XianZai - ZhenYanShiJian > BOSSZhenYan then
                --判断真言是否释放
                ZhenYan = 0
            end
            if Duanjin == 0 then
                --判断断筋诀冷却是否结束
                JiNeng_Down(djj)
                JiNeng_Up(djj)
                Duanjin = 1
                DuanjinShiJian = GetRunningTime()
            elseif Duanjin == 1 and HeiRen == 1 and ZhenYan == 1 and JinZhen == 1 and JuFeng == 1 and XianZai - DuanjinShiJian > BOSSYanChi then
                --判断断筋诀是否释放
                Duanjin = 0
            end
            if JinZhen == 0 then
                --判断金轮阵冷却是否结束
                JiNeng_Down(jlz)
                JiNeng_Up(jlz)
                JinZhen = 1
                JinZhenShiJian = GetRunningTime()
            elseif Duanjin == 1 and HeiRen == 1 and ZhenYan == 1 and JinZhen == 1 and JuFeng == 1 and XianZai - JinZhenShiJian > JinZhenYanChi then
                --判断金轮阵是否释放
                JinZhen = 0
            end
            Sleep(1)
            XianZai = GetRunningTime()--得到延迟脚本过程的绝对时间
        end
        XianZai_ZhenShu = XianZai_ZhenShu + ZhenShu
    end
end

--BOSS有飓风
function BOSSYanChi2(ZhenShu)
    if IsKeyLockOn(LED) then
        --判断是否灯亮
        XianZai = GetRunningTime()--得到延迟脚本开始时间
        while XianZai - KaiShi < (XianZai_ZhenShu + ZhenShu) / 60 * 1000 and IsKeyLockOn(LED)
        do
            GuanBi(BOSSButton)
            if HeiRen == 0 then
                --判断黑人冷却是否结束
                JiNeng_Down(hr)
                JiNeng_Up(hr)
                HeiRen = 1
                HeiRenShiJian = GetRunningTime()
            elseif Duanjin == 1 and HeiRen == 1 and ZhenYan == 1 and JinZhen == 1 and JuFeng == 1 and XianZai - HeiRenShiJian > HeiRenYanChi then
                --判断黑人是否释放
                HeiRen = 0
            end
            if ZhenYan == 0 then
                --判断真言冷却是否结束
                JiNeng_Down(zy)
                JiNeng_Up(zy)
                ZhenYan = 1
                ZhenYanShiJian = GetRunningTime()
            elseif Duanjin == 1 and HeiRen == 1 and ZhenYan == 1 and JinZhen == 1 and JuFeng == 1 and XianZai - ZhenYanShiJian > BOSSZhenYan then
                --判断真言是否释放
                ZhenYan = 0
            end
            if Duanjin == 0 then
                --判断断筋诀冷却是否结束
                JiNeng_Down(djj)
                JiNeng_Up(djj)
                Duanjin = 1
                DuanjinShiJian = GetRunningTime()
            elseif Duanjin == 1 and HeiRen == 1 and ZhenYan == 1 and JinZhen == 1 and JuFeng == 1 and XianZai - DuanjinShiJian > BOSSJianGe / 3 then
                --判断断筋诀是否释放
                CiShu = CiShu + 1
                if CiShu % 3 == 0 then
                    Duanjin = 1
                    DuanjinShiJian = GetRunningTime()
                else
                    Duanjin = 0
                end
            end
            if JinZhen == 0 then
                --判断金轮阵冷却是否结束
                JiNeng_Down(jlz)
                JiNeng_Up(jlz)
                JinZhen = 1
                JinZhenShiJian = GetRunningTime()
            elseif Duanjin == 1 and HeiRen == 1 and ZhenYan == 1 and JinZhen == 1 and JuFeng == 1 and XianZai - JinZhenShiJian > JinZhenYanChi then
                --判断金轮阵是否释放
                JinZhen = 0
            end
            if JuFeng == 0 then
                --判断飓风破冷却是否结束
                JiNeng_Down(jfp)
                JiNeng_Up(jfp)
                JuFeng = 1
                JuFengShiJian = GetRunningTime()
            elseif Duanjin == 1 and HeiRen == 1 and ZhenYan == 1 and JinZhen == 1 and JuFeng == 1 and CiShu % 3 == 0 and DuanjinShiJian > JuFengShiJian then
                --判断飓风破是否释放
                JuFeng = 0
            end
            Sleep(1)
            XianZai = GetRunningTime()--得到延迟脚本过程的绝对时间
        end
        XianZai_ZhenShu = XianZai_ZhenShu + ZhenShu
    end
end

---------------------------------------------------------------------------------------------------------
------------------------------------------------------主程序----------------------------------------------
function OnEvent(event, arg)
    if (event == "MOUSE_BUTTON_PRESSED" and arg == PaoLu and not IsModifierPressed(FuZhu)) then
        --跑路宏
        if QieHuan == 1 then
            KaiGuan = 1
        end
        KaiQi()
        Sleep(100)--等待宏开始
        while IsKeyLockOn(LED)
        do
            KaiShi = GetRunningTime()
            XianZai_ZhenShu = 0
            ZhenYan = 0
            HeiRen = 0
            PaoLuYanChi(36000)--10分钟循环，可增加延迟
        end
    end
    if (event == "MOUSE_BUTTON_PRESSED" and arg == XiaoGuai and not IsModifierPressed(FuZhu)) then
        --小怪宏
        if QieHuan == 1 then
            KaiGuan = 1
        end
        KaiQi()
        Sleep(100)--等待宏开始
        while IsKeyLockOn(LED)
        do
            PressKey(ZhanLi)
            JiNeng_Down(djj)
            KaiShi = GetRunningTime()
            XianZai_ZhenShu = 0
            JinZhen = 0
            XuanMu = 0
            ZhenYan = 0
            HeiRen = 0
            XiaoGuaiYanChi(30)--10分钟循环，可增加延迟
            JuFeng = 0
            XiaoGuaiYanChi(36000)--10分钟循环，可增加延迟
            JiNeng_Up(djj)
            ReleaseKey(ZhanLi)
        end
    end
    if (event == "MOUSE_BUTTON_PRESSED" and arg == BOSS and not IsModifierPressed(FuZhu)) then
        --王战宏
        if QieHuan == 1 then
            KaiGuan = 1
        end
        KaiQi()
        Sleep(100)--等待宏开始
        while IsKeyLockOn(LED)
        do
            PressKey(ZhanLi)
            DuanjinKaiShi = GetRunningTime()
            KaiShi = GetRunningTime()
            XianZai_ZhenShu = 0
            CiShu = 1
            Duanjin = 0
            JinZhen = 0
            ZhenYan = 0
            HeiRen = 0
            JuFeng = 0
            if BOSSJianGe == 0 then
                JuFeng = 1
                BOSSYanChi1(36000)--10分钟循环，可增加延迟
            else
                BOSSYanChi2(2 * BOSSJianGe / 3)
                JuFeng = 0
                BOSSYanChi2(36000)--10分钟循环，可增加延迟
            end
            ReleaseMouseButton(1)
            ReleaseKey(ZhanLi)
        end
    end
    if (event == "MOUSE_BUTTON_PRESSED" and arg == 2 and IsModifierPressed(FuZhu)) then
        --辅助键+右键赌博
        k = 50
        while k > 0
        do
            PressAndReleaseMouseButton(3)
            Sleep(5)
            k = k - 1
        end
    end
    if (event == "MOUSE_BUTTON_PRESSED" and arg == 4 and IsModifierPressed(FuZhu)) then
        --辅助键+G4键分解
        FenJie()
    end
    if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsModifierPressed(FuZhu)) then
        --辅助键+左键拾取
        k = 25
        while k > 0
        do
            PressAndReleaseMouseButton(1)
            Sleep(15)
            k = k - 1
        end
    end
end